/*
 * 
 * 
 * 
 */
package com.hboxs.asl.entity;

import com.fasterxml.jackson.annotation.JsonProperty;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotEmpty;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;

/**
 * Entity - 属性
 */
@Entity
@Table(name = "xx_attribute")
@SequenceGenerator(name = "sequenceGenerator", sequenceName = "xx_attribute_sequence")
public class Attribute extends OrderEntity {

    private static final long serialVersionUID = 2447794131117928367L;

    /**
     * 名称
     */
    private String name;

    /**
     * 属性序号
     */
    private Integer propertyIndex;

    /**
     * 绑定分类
     */
    private ProductCategory productCategory;

    /**
     * 可选项
     */
    private List<String> options = new ArrayList<String>();

    /**
     * 获取名称
     *
     * @return 名称
     */
    @JsonProperty
    @NotEmpty
    @Length(max = 200)
    @Column(nullable = false)
    public String getName() {
        return name;
    }

    /**
     * 设置名称
     *
     * @param name 名称
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取属性序号
     *
     * @return 属性序号
     */
    @Column(nullable = false, updatable = false)
    public Integer getPropertyIndex() {
        return propertyIndex;
    }

    /**
     * 设置属性序号
     *
     * @param propertyIndex 属性序号
     */
    public void setPropertyIndex(Integer propertyIndex) {
        this.propertyIndex = propertyIndex;
    }

    /**
     * 获取绑定分类
     *
     * @return 绑定分类
     */
    @NotNull(groups = Save.class)
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(nullable = false, updatable = false)
    public ProductCategory getProductCategory() {
        return productCategory;
    }

    /**
     * 设置绑定分类
     *
     * @param productCategory 绑定分类
     */
    public void setProductCategory(ProductCategory productCategory) {
        this.productCategory = productCategory;
    }

    /**
     * 获取可选项
     *
     * @return 可选项
     */
    @JsonProperty
    @NotEmpty
    @ElementCollection
    @CollectionTable(name = "xx_attribute_option")
    public List<String> getOptions() {
        return options;
    }

    /**
     * 设置可选项
     *
     * @param options 可选项
     */
    public void setOptions(List<String> options) {
        this.options = options;
    }

}